package com.uwaterloo.interviewme;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.uwaterloo.interviewme.am.ApplicationManager;
import com.uwaterloo.interviewme.common.DBConstants;
import com.uwaterloo.interviewme.exception.ServerException;
import com.uwaterloo.interviewme.model.Interview;

/**
 * The view that is responsible for rendering detail interview information Detail Information
 * including: -Company Name -Job Position -Location of the interview -Time -Length of the interview
 * -Status -Job description
 * 
 * The view will be called by the {@link InterviewListRender} when users need to have a more
 * comprehensive knowledge of the interview. Upon requesting this view, the
 * {@link InterviewListRender} will pass down a row id so that {@link DetailInterviewRender} knows
 * which interview the user is requesting
 */
public class DetailInterviewRender extends Activity {

	/** The row id. */
	private int rowID;

	/** The Detail Interview Render holds a reference to the application manager */
	private ApplicationManager am;

	/** A bunch of text that need to be set */
	private TextView cNameText, posText, locText, timeText, typeText, lenText, staText, jDescText;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.interview_detail);

		/* Initialize Application Manager */
		am = ApplicationManager.getInstance();
		am.setContext(this);

		/* Get the row id that have been past down from the previous view */
		Bundle extras = getIntent().getExtras();
		rowID = extras.getInt(DBConstants.ROW_ID);

		/* Initialize all the text views that need to be rendered */
		cNameText = (TextView) findViewById(R.id.cNameText);
		posText = (TextView) findViewById(R.id.posText);
		locText = (TextView) findViewById(R.id.locText);
		timeText = (TextView) findViewById(R.id.timeText);
		typeText = (TextView) findViewById(R.id.typeText);
		lenText = (TextView) findViewById(R.id.lenText);
		staText = (TextView) findViewById(R.id.staText);
		jDescText = (TextView) findViewById(R.id.jDescText);

		renderInterviewDetail(rowID);

	}

	/**
	 * Render interview detail.
	 * 
	 * @param rowID
	 */
	private void renderInterviewDetail(int rowID) {
		/* Get the interview for this particular row from AM */
		try {
			Interview interview = am.loadInterview(rowID);
			/* Start rendering */
			cNameText.setText(interview.getCompanyName());
			posText.setText(interview.getPosition());
			locText.setText(interview.getLocation());
			timeText.setText(interview.getTime());
			typeText.setText(interview.getDetailInfo().getType());
			lenText.setText(interview.getDetailInfo().getLength());
			staText.setText(interview.getDetailInfo().getStatus());
			jDescText.setText(interview.getDetailInfo().getJobDesc());
		} catch (ServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
